package gameobject;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.Timer;
import simulation.Game;

/**
 * StrongEnemy can shoot missiles at the player in a random
 * fashion. Otherwise the same as a normal enemy.
 *
 */
public class StrongEnemy extends Sprite implements ActionListener {
    protected Timer myTimer;
    protected List<Sprite> mySprites;

    /**
     * Emtpy constructor.
     */
    public StrongEnemy() {
        super();
    }

    /**
     * Constructs a StrongEnemy to shoot at the player.
     * @param game which this belongs to
     * @param dx starting x acc
     * @param dy starting y acc
     * @param speed starting speed
     * @param hp starting health
     * @param damage starting damage to inflict
     * @param m list of missiles
     */
    public StrongEnemy(Game game, Number dx, Number dy,
            Number speed, Number hp, Number damage, List<Sprite> m) {
        super(game, dx, dy, speed, hp, damage);
        setDamageOnCollide(3);
        setHP(6);
        //dropRate = 0.4; //higher dropRate
        mySprites = m;
        //timer for firing missiles
        myTimer = new Timer(1500, this);
    }

    @Override
    public StrongEnemy createProduct(Game game, String[] args) {
        Number[] parameters = convertToParameters(args);
        StrongEnemy myProduct = new StrongEnemy(game,
                parameters[findIndex("dx")],
                parameters[findIndex("dy")], parameters[findIndex("speed")],
                parameters[findIndex("HP")],
                parameters[findIndex("damage")], null);
        myProduct.setImage(args[findIndex("image")]);
        return myProduct;
    }

    @Override
    public void die() {
        super.die();
        myTimer.stop();
    }

    /**
     * Makes the StrongEnemy fire missiles
     * randomly.
     * @param e an event
     */
    public void actionPerformed(ActionEvent e) {
        double angle = Math.random() * Math.PI / 3 - Math.PI / 6;
        //enemyMissiles.add(new EnemyBasicMissile(getX() + width/2, getY() + height, angle, false));
    }

    @Override
    public void activate() {
        myTimer.start();
    }
}
